package com.epam.manager.backingbeans;

import javax.ejb.EJB;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import com.epam.DAO.RequestDAO;
import com.epam.entity.Request;

public abstract class RequestController {
	
	@EJB	
	protected RequestDAO requestDAO;
	
	protected DataModel<Request> requests;
	
	protected int firstRow;
	protected int totalPages;
	protected int currentPage;

	protected int rowsPerPage = 5; 
	protected int totalRows;
	
	protected RequestController(){
		requests = new ListDataModel<Request>();
	}
	
	public void pageFirst() {
        page(0);
    }

	public void pageNext() {
        page(firstRow + rowsPerPage);
    }

	public void pagePrevious() {
        page(firstRow - rowsPerPage);
    }

	public void pageLast() {
        page(totalRows - ((totalRows % rowsPerPage != 0) ? totalRows % rowsPerPage : rowsPerPage));
    }

    private void page(int firstRow) {
        this.firstRow = firstRow;
    }
	
    public int getTotalRows() {
        return totalRows;
    }

    public int getFirstRow() {
        return firstRow;
    }

    public int getRowsPerPage() {
        return rowsPerPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getTotalPages() {
        return totalPages;
    }
        
    public abstract DataModel<Request> getRequests();
}
